package com.todo.reward.infrastructure.repository.impl;

import com.todo.common.common.entity.response.page.PageResult;
import com.todo.reward.common.enums.RewardDispatchStatusEnum;
import com.todo.reward.infrastructure.entity.condition.RewardDispatchRecordCondition;
import com.todo.reward.infrastructure.entity.po.RewardDispatchRecordPO;
import com.todo.reward.infrastructure.mapper.RewardDispatchRecordMapper;
import com.todo.reward.infrastructure.repository.RewardDispatchRecordRepository;
import org.springframework.stereotype.Repository;

import javax.annotation.Resource;

/**
 * @author azhebuxing
 * @date 2025/2/12 22:56
 * @description
 */
@Repository
public class RewardDispatchRecordRepositoryImpl implements RewardDispatchRecordRepository {

    @Resource
    private RewardDispatchRecordMapper rewardDispatchRecordMapper;

    @Override
    public Boolean insertRewardDispatchRecordPO(RewardDispatchRecordPO rewardDispatchRecordPO) {
        if (rewardDispatchRecordPO == null) {
            return false;
        }
        if (rewardDispatchRecordPO.getTemplateId() == null || rewardDispatchRecordPO.getRewardType() == null || rewardDispatchRecordPO.getUserId() == null
                || rewardDispatchRecordPO.getDispatchBizUk() == null || rewardDispatchRecordPO.getDispatchAmount() == null) {
            return false;
        }
        return rewardDispatchRecordMapper.insertRewardDispatchRecordPO(rewardDispatchRecordPO);
    }

    @Override
    public Boolean updateRewardDispatchRecordPO(RewardDispatchRecordPO rewardDispatchRecordPO) {
        if (rewardDispatchRecordPO == null || rewardDispatchRecordPO.getId() == null) {
            return false;
        }
        return rewardDispatchRecordMapper.updateRewardDispatchRecordPO(rewardDispatchRecordPO);
    }

    @Override
    public Boolean removeRewardDispatchRecordPOById(Long id) {
        if (id == null || id < 0) {
            return false;
        }
        return rewardDispatchRecordMapper.removeRewardDispatchRecordPOById(id);
    }

    @Override
    public RewardDispatchRecordPO queryRewardDispatchRecordPOById(Long id) {
        if (id == null || id < 0) {
            return null;
        }
        return rewardDispatchRecordMapper.queryRewardDispatchRecordPOById(id);
    }

    @Override
    public Boolean updateRewardDispatchRecordStatusById(Long id, RewardDispatchStatusEnum oldStatus, RewardDispatchStatusEnum newStatus) {
        if (id == null || id < 0 || oldStatus == null || newStatus == null) {
            return false;
        }
        return rewardDispatchRecordMapper.updateRewardDispatchRecordStatusById(id, oldStatus.getType(), newStatus.getType());
    }

    @Override
    public PageResult<RewardDispatchRecordPO> queryRewardDispatchRecordPOByCondition(RewardDispatchRecordCondition rewardDispatchRecordCondition) {
        return null;
    }
}
